import 'package:flutter/material.dart';
import 'package:flutter_architecture_samples_vanilla/models.dart';
import 'package:flutter_architecture_samples_vanilla/screen/add_edit_screen.dart';
import 'package:flutter_architecture_samples_vanilla/widgets/typedefs.dart';
import 'package:todos_app_core/todos_app_core.dart';

class DetailScreen extends StatelessWidget {
  final Todo todo;
  final TodoUpdater updateTodo;
  final TodoAdder addTodo;
  final Function onDelete;
  const DetailScreen(
      {required this.todo,
      required this.addTodo,
      required this.updateTodo,
      required this.onDelete,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) => Scaffold(
      appBar: AppBar(
        title: Text(ArchSampleLocalizations.of(context)!.todoDetails),
        actions: [
          IconButton(
            onPressed: () {
              onDelete();
              Navigator.pop(context, todo);
            },
            icon: Icon(Icons.delete),
          )
        ],
      ),
      body: Padding(
        padding: EdgeInsets.all(16),
        child: ListView(
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(
                    padding: EdgeInsets.only(right: 8),
                    child: Checkbox(
                      value: todo.complete,
                      key: ArchSampleKeys.todoItemCheckbox(todo.id),
                      onChanged: (complete) {
                        updateTodo(todo, complete: !todo.complete);
                      },
                    )),
                Expanded(
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                      Padding(
                        padding: EdgeInsets.only(bottom: 16, top: 8),
                        child: Text(
                          todo.task,
                          key: ArchSampleKeys.detailsTodoItemTask,
                        ),
                      ),
                      Text(
                        todo.note,
                        key: ArchSampleKeys.detailsTodoItemNote,
                        style: Theme.of(context).textTheme.titleMedium,
                      )
                    ]))
              ],
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
          key: ArchSampleKeys.editTodoFab,
          child: Icon(Icons.edit),
          onPressed: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (context) {
              return AddEditScreen(
                  addTodo: addTodo, todo: todo, updateTodo: updateTodo);
            }));
          }));
}
